import 'package:built_collection/built_collection.dart';
import 'package:mobile_app.core/core/domain/entities/email_app.dart';
import 'package:mobile_app.core/core/domain/entities/learning_content/lexical_item/lexical_item.dart';
import 'package:mobile_app.home.core/core/domain/entities/card_actions/mistake_report_card_action.dart';
import 'package:mobile_app.home.core/core/domain/helpers/is_mistake_report_card_action_reasonable/helper.dart';

abstract class CreateMistakeReportCardActionIfReasonable {
  MistakeReportCardAction? call({
    required LexicalItem lexicalItem,
    required BuiltList<EmailApp> availableEmailApps,
  });
}

class CreateMistakeReportCardActionIfReasonableImpl
    implements CreateMistakeReportCardActionIfReasonable {
  const CreateMistakeReportCardActionIfReasonableImpl({
    required IsMistakeReportCardActionReasonable isMistakeReportCardActionReasonable,
  }) : _isMistakeReportCardActionReasonable = isMistakeReportCardActionReasonable;

  final IsMistakeReportCardActionReasonable _isMistakeReportCardActionReasonable;

  @override
  MistakeReportCardAction? call({
    required LexicalItem lexicalItem,
    required BuiltList<EmailApp> availableEmailApps,
  }) {
    final cardActionReasonable = _isMistakeReportCardActionReasonable(
      lexicalItem: lexicalItem,
    );

    if (!cardActionReasonable) {
      return null;
    }

    final cardAction = MistakeReportCardAction(
      availableEmailApps: availableEmailApps,
    );

    return cardAction;
  }
}
